﻿using System;
using OOXMLGenerator.Enums;

namespace OOXMLGenerator.DataStructure
{
    /// <summary>
    /// Is a custom Section Content with PartContentType.BillOfMaterials Type
    /// </summary>
    public class BOMSectionContent : SectionContent
    {
        /// <summary>
        /// Empty Constructor - initializes a new instance of the BOMSectionContent Class.
        /// Properties settings:
        /// Header = Properties.Resources.Header_BillOfMaterials;
        /// Type = PartContentType.BillOfMaterials
        /// Content = new instance of PartDataSet.PartBOMDataTable
        /// </summary>
        public BOMSectionContent()
        {
            base.Header = Properties.Resources.Header_BillOfMaterials;
            base.Type = PartContentType.BillOfMaterials;
            base.Content = new PartDataSet.PartBOMDataTable();
        }

        /// <summary>
        /// Initializes a new instance of the BOMSectionContent Class.
        /// Properties settings:
        /// Header = header
        /// Type = PartContentType.BillOfMaterials
        /// Content = new instance of PartDataSet.PartBOMDataTable
        /// </summary>
        /// <param name="header">BOM Section Content header</param>
        public BOMSectionContent(string header)
        {
            base.Header = header;
            base.Type = PartContentType.BillOfMaterials;
            base.Content = new PartDataSet.PartBOMDataTable();
        }

        /// <summary>
        /// Adds a row to BOM Section Content initialized with given parameters
        /// </summary>
        /// <param name="sequence">sort order</param>
        /// <param name="partNumber">part number</param>
        /// <param name="name">part name</param>
        /// <param name="revision">major revision</param>
        /// <param name="quantity">quantity of part BOM</param>
        public void AddBOMItem(int? sequence, string partNumber, string name, string revision, double? quantity)
        {
            PartDataSet.PartBOMRow bomRow = ((PartDataSet.PartBOMDataTable)base.Content).NewPartBOMRow();
            if (sequence != null)
                bomRow.sort_order = (int)sequence;
            bomRow.item_number = partNumber;
            bomRow.name = name;
            bomRow.major_rev = revision;
            if (quantity != null)
                bomRow.quantity = (double)quantity;
            ((PartDataSet.PartBOMDataTable)base.Content).AddPartBOMRow(bomRow);
        }
    }
}
